﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ComUIControl
{
    public partial class FormOnWaitting : Form
    {

        private int x0 = 0;
        private int y0 = 0;

        public FormOnWaitting()
        {
            InitializeComponent();
            this.ControlBox = false;   // 设置不出现关闭按钮
            x0 = labelWaitInfo.Location.X;
            y0 = labelWaitInfo.Location.Y;
        }

        private delegate void SetTipHandler(string text);
        public void SetTip(string text)
        {
            if (this.labelWaitInfo.InvokeRequired)
            {
                this.BeginInvoke(new SetTipHandler(SetTip), text);
            }
            else
            {
                this.labelWaitInfo.Text = text;
            }
        }

        public void ReLayout()
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new Action(ReLayout));
            }
            else
            {
                Rectangle rect = new Rectangle();
                rect = Screen.GetWorkingArea(this);
                int width = rect.Width;//屏幕宽
                int height = rect.Height;//屏幕高

                if (labelWaitInfo.Width > 264 && labelWaitInfo.Height >= 50)
                {
                    this.Width = x0 * 2 + labelWaitInfo.Width;
                    this.Height = y0 * 2 + labelWaitInfo.Height;
                    int x = (width - this.Width) / 2;
                    int y = (height - this.Height) / 2;
                    this.Location = new Point(x, y);
                }
                else
                {
                    this.Width = labelWaitInfo.Location.X * 2 + labelWaitInfo.Width;
                    int x = (width - this.Width) / 2;
                    this.Left = x;
                }
            }
        }

        private void FormOnWaitting_Load(object sender, EventArgs e)
        {
            ReLayout();    
        }
    }
}
